<?php
namespace app\api\controller;

use think\Request;

/**
 * @SWG\Swagger(
 *     schemes={"https","http"},
 *     host="bike.wei-yong.com/api/Xixiche",
 *     consumes={"multipart/form-data"},
 *     produces={"application/json"},
 *     @SWG\Info(
 *       version="1.0",
 *       title="会议行程帮",
 *       description="会议行程帮接口文档<br> 以后就在这里愉快的对接口把!<br>"
 *     ),
 *
 *     @SWG\Tag(
 *       name="Master",
 *       description="司机端",
 *     ),
 *     
 *     @SWG\Tag(
 *       name="User",
 *       description="嘉宾端",
 *     ),
 *     
 *     @SWG\Tag(
 *       name="Admin",
 *       description="员工端",
 *     ),
 * )
 */
class Meeting extends Base
{

    public function getdistance($lng1, $lat1, $lng2, $lat2)
    {
        //将角度转为弧度
        $radLat1 = deg2rad($lat1); //deg2rad()函数将角度转换为弧度
        $radLat2 = deg2rad($lat2);
        $radLng1 = deg2rad($lng1);
        $radLng2 = deg2rad($lng2);
        
        $a = $radLat1 - $radLat2;
        $b = $radLng1 - $radLng2;
        $s = 2 * asin(sqrt(pow(sin($a / 2), 2) + cos($radLat1) * cos($radLat2) * pow(sin($b / 2), 2))) * 6378.137 * 1000;
        return $s;
    }

    /**
     * 定位坐标
     * lat - 当前纬度
     * lon - 当前纬度
     * **/
    public function locationAddress()
    {
        $post = request()->only(['latitude', 'longitude'], 'post');
        //品牌
        if (empty($post['latitude']) and empty($post['longitude'])) {
            err('经纬度不能为空');
        }
        
        //根据经纬度获取地区
        $place_url = 'http://api.map.baidu.com/geocoder/v2/?ak=hN63t3PFLM0TEFB50dHlQppj70xdUtA6&callback=renderReverse&location=' . $post['latitude'] . ',' . $post['longitude'] . '&output=json&pois=1';
        $json_place = file_get_contents($place_url);
        $json_places = str_replace("renderReverse&&renderReverse(", "", $json_place);
        $newstr = substr($json_places, 0, strlen($json_places) - 1);
        $place_arr = json_decode($newstr);
        $area = $place_arr->result->addressComponent->city;
        if ( ! $area) {
            err('定位失败');
        }
        suc($area);
    }
    
    // 发送手机验证码
    public function checkMobileSend()
    {}
    
    // 员工端 - 登陆
    public function loginAdmin()
    {
        $post = request()->only(['mobile', 'verify_code', 'time', 'mid'], 'post');
        
        if (empty($post['mobile'])) {
            err('请输入手机号码');
        }
        
        $mid_s = md5($post['mobile'] . $post['verify_code'] . $post['time'] . $this->signKey);
        
        $info = db('user')->where(['mobile'=>$post['mobile'], 'status'=>1, 'admin_id'=>[['=', 1003], ['=', 1004], 'or']])->find();
        
        if (empty($info)) {
            err('该账号无登陆权限');
        }
        if ($mid_s != $post['mid']) {
            err('验证码错误');
        }
        suc('验证成功');
    }

    /**
     * @SWG\Post(
     *   path="/meetingAbout",
     *   tags={"Admin"},
     *   summary="员工端 - 大会简介",
     *   description="员工端 - 大会简介 - 黎勇斌",
     *   @SWG\Parameter(name="mstr", description="加密KEY", in="formData", required=true, type="string"),
     *   @SWG\Response(
     *       response=200,
     *       description="成功返回数据",
     *       @SWG\Header(header="meeting_id", type="string", description="会议ID"),
     *       @SWG\Header(header="meeting_img", type="string", description="会议大图"),
     *       @SWG\Header(header="meeting_sign", type="string", description="报名时间"),
     *       @SWG\Header(header="meeting_going", type="string", description="进行时间"),
     *       @SWG\Header(header="meeting_address", type="string", description="开会地址"),
     *       @SWG\Header(header="meeting_going_time", type="string", description="具体开会时间"),
     *       
     *       @SWG\Header(header="people_hits", type="string", description="浏览"),
     *       @SWG\Header(header="people_enrolments", type="string", description="报名"),
     *       @SWG\Header(header="people_checks", type="string", description="签到"),
     *       
     *       @SWG\Header(header="hotel_allHotel", type="string", description="全部酒店"),
     *       @SWG\Header(header="hotel_allHotelNo", type="string", description="全部酒店-未安排"),
     *       @SWG\Header(header="hotel_todayHotel", type="string", description="今日酒店"),
     *       @SWG\Header(header="hotel_todayHotelYes", type="string", description="今日酒店 - 已安排"),
     *       @SWG\Header(header="hotel_tomorrowHotel", type="string", description="明日酒店"),
     *       @SWG\Header(header="hotel_tomorrowHotelYes", type="string", description="明日酒店 - 安排"),
     *       
     *       @SWG\Header(header="allCar", type="string", description="全部用车"),
     *       @SWG\Header(header="allCarNo", type="string", description="全部用车 - 未安排"),
     *       @SWG\Header(header="todayCar", type="string", description="今日用车"),
     *       @SWG\Header(header="todayCarYes", type="string", description="今日用车 - 已安排"),
     *       @SWG\Header(header="tomorrowCar", type="string", description="明日用车"),
     *       @SWG\Header(header="tomorrowCarYes", type="string", description="明日用车 - 已安排"),
     
     *       @SWG\Header(header="travel", type="string", description="嘉宾行程"),
     *       @SWG\Header(header="flight", type="string", description="嘉宾航班"),
     *   )
     * )
     */
    public function meetingAbout()
    {
        $res = [];
        $now = time();
        // 今天
        $todStart = strtotime(date('Y-m-d 00:00:00', $now));
        $todEnd = strtotime(date('Y-m-d 23:59:59', $now));
        // 明天
        $tomTime = strtotime('+1 day', $now);
        $tomStart = strtotime(date('Y-m-d 00:00:00', $tomTime));
        $tomEnd = strtotime(date('Y-m-d 23:59:59', $tomTime));
        
        // 会议信息
        $info = db('meeting_details')->where(['status'=>1, 'admin_id'=>1004])->find();
        // 会议介绍
        $res['meeting'] = db('meeting_details')->where(['status'=>1, 'admin_id'=>1004])->field('id,img,sign_date,sign_date_end,going_date,going_date_end,address,going_time')->find();
        $res['meeting']['img'] = json_decode($res['meeting']['img']);
        if ( ! empty($res['meeting'])) {
            $res['meeting']['sign'] = date('Y/m/d', $res['meeting']['sign_date']) . ' - ' . date('Y/m/d', $res['meeting']['sign_date_end']);
            $res['meeting']['going'] = date('Y/m/d', $res['meeting']['going_date']) . ' - ' . date('Y/m/d', $res['meeting']['going_date_end']);
            $res['meeting']['going_time'] = date('Y-m-d H:i', $res['meeting']['going_time']);
        }
        //会议经度
        $res['meeting']['longitude'] = $info['longitude'];
        //会议纬度
        $res['meeting']['latitude'] = $info['latitude'];
        
        // 会议人数统计
        $res['people'] = db('meeting_statistics')->where(['meeting_id'=>$info['id']])
            ->field('create_time,hits,enrolments,signs')
            ->order('create_time desc')
            ->limit(5)
            ->select();
        if ( ! empty($res['people'])) {
            foreach ($res['people'] as $key=>$val) {
                $res['people'][$key]['create_time'] = date('Y-m-d', $val['create_time']);
            }
        }
        $res['statistics']['hits'] = db('meeting_statistics')->where(['meeting_id'=>$info['id']])->sum('hits');
        $res['statistics']['enrolments'] = db('meeting_statistics')->where(['meeting_id'=>$info['id']])->sum('enrolments');
        $res['statistics']['signs'] = db('meeting_statistics')->where(['meeting_id'=>$info['id']])->sum('signs');
        // 会议酒店需求
        // 酒店需求 - 全部
        $res['hotel']['allHotel'] = db('meeting_travel')->where(['admin_id'=>1004, 'meeting_id'=>$info['id']])->count();
        // 未安排
        $res['hotel']['allHotelNo'] = db('meeting_travel')->where(['admin_id'=>1004, 'meeting_id'=>$info['id'], 'hotel_id'=>['exp', 'is null']])->count();
        // 今日 - 全部
        $res['hotel']['todayHotel'] = db('meeting_travel')->where(['admin_id'=>1004, 'meeting_id'=>$info['id'], 'go_start_date'=>['between', [$todStart, $todEnd]]])->count();
        // 已安排
        $res['hotel']['todayHotelYes'] = db('meeting_travel')->where(['admin_id'=>1004, 'meeting_id'=>$info['id'], 'go_start_date'=>['between', [$todStart, $todEnd]], 'hotel_id'=>['exp', 'is not null']])->count();
        
        // 明日 - 全部
        $res['hotel']['tomorrowHotel'] = db('meeting_travel')->where(['admin_id'=>1004, 'meeting_id'=>$info['id'], 'go_start_date'=>['between', [$tomStart, $tomEnd]]])->count();
        // 已安排
        $res['hotel']['tomorrowHotelYes'] = db('meeting_travel')->where(['admin_id'=>1004, 'meeting_id'=>$info['id'], 'go_start_date'=>['between', [$tomStart, $tomEnd]], 'hotel_id'=>['exp', 'is not null']])->count();
        
        // 会议用车需求
        // 用车需求 - 全部
        $res['car']['allCar'] = db('meeting_car')->where(['admin_id'=>1004, 'meeting_id'=>$info['id']])->count();
        // 未安排
        $res['car']['allCarNo'] = db('meeting_car')->where(['admin_id'=>1004, 'meeting_id'=>$info['id'], 'arrange_status'=>0])->count();
        
        // 今日 - 全部
        $res['car']['todayCar'] = db('meeting_car')->where(['admin_id'=>1004, 'meeting_id'=>$info['id'], 'start_time'=>['between', [$todStart, $todEnd]]])->count();
        // 已安排
        $res['car']['todayCarYes'] = db('meeting_car')->where(['admin_id'=>1004, 'meeting_id'=>$info['id'], 'start_time'=>['between', [$todStart, $todEnd]], 'arrange_status'=>1])->count();
        
        // 明日 - 全部
        $res['car']['tomorrowCar'] = db('meeting_car')->where(['admin_id'=>1004, 'meeting_id'=>$info['id'], 'start_time'=>['between', [$tomStart, $tomEnd]]])->count();
        // 已安排
        $res['car']['tomorrowCarYes'] = db('meeting_car')->where(['admin_id'=>1004, 'meeting_id'=>$info['id'], 'start_time'=>['between', [$tomStart, $tomEnd]], 'arrange_status'=>1])->count();
        
        // 嘉宾行程 - 已确定
        $res['travel'] = db('meeting_travel')->where(['admin_id'=>1004, 'meeting_id'=>$info['id'], 'go_flight_number'=>['exp', 'is not null']])->count();
        
        // 嘉宾航班 - 未确定
        $res['flight'] = db('meeting_travel')->where(['admin_id'=>1004, 'meeting_id'=>$info['id'], 'go_flight_number'=>['exp', 'is null']])->count();
        
        suc('查询成功', $res);
    }

    /**
     * @SWG\Post(
     *   path="/useCar",
     *   tags={"Admin"},
     *   summary="员工端 - 用车需求详情",
     *   description="员工端 - 用车需求详情 - 黎勇斌",
     *   @SWG\Parameter(name="mstr", description="加密KEY", in="formData", required=true, type="string"),
     *   @SWG\Parameter(name="meeting_id", description="会议ID", in="formData", required=true, type="string"),
     *   @SWG\Parameter(name="time", description="// 查询时间（0：全部，1：今天，2：明天）", in="formData", required=true, type="string"),
     *   @SWG\Parameter(name="status", description="// 安排与否（0：全部，1：已安排，2：未安排）", in="formData", required=true, type="string"),
     *   @SWG\Parameter(name="travel", description="// 用车时长（0：单程，1：半天，2：全天）", in="formData", required=true, type="string"),
     *   @SWG\Parameter(name="purpose", description="// 用途（0：接机，1：送机，2：市内）", in="formData", required=true, type="string"),
     *   @SWG\Response(
     *       response=200,
     *       description="成功返回数据",
     *       @SWG\Header(header="name", type="string", description="姓名"),
     *       @SWG\Header(header="start_time", type="string", description="时间pur"),
     *       @SWG\Header(header="purpose", type="string", description="用途（0：接机，1：送机，2：市内）"),
     *       @SWG\Header(header="nickname", type="string", description="司机"),
     *   )
     * )
     */
    public function useCar()
    {
        $now = time();
        
        $todStart = strtotime(date('Y-m-d 00:00:00', $now));
        $todEnd = strtotime(date('Y-m-d 23:59:59', $now));
        
        $tomTime = strtotime('+1 day', $now);
        $tomStart = strtotime(date('Y-m-d 00:00:00', $tomTime));
        $tomEnd = strtotime(date('Y-m-d 23:59:59', $tomTime));
        
        if (request()->isPost()) {
            $post = input('post.');
            if ( ! isset($post['page'])) {
                $post['page'] = 0;
            }
            if ( ! isset($post['pagesize'])) {
                $post['pagesize'] = 10;
            }
            $page = $post['page'];
            $pagesize = $post['pagesize'];
            $where = [];
            $where['a.admin_id'] = 1004;
            $where['a.meeting_id'] = $post['meeting_id'];
            if ( ! empty($post['name'])) {
                $where['b.name'] = ['like', '%' . $post['name'] . '%'];
            }
            // 查询时间（0：全部，1：今天，2：明天）
            if ($post['time'] == 1) {
                $where['start_time'] = ['between', [$todStart, $todEnd]];
            } elseif ($post['time'] == 2) {
                $where['start_time'] = ['between', [$tomStart, $tomEnd]];
            }
            // 用途（0：接机，1：送机，2：市内）
            if ( ! empty($post['purpose'])) {
                $where['purpose'] = $post['purpose'];
            } else {
                $where['purpose'] = 0;
            }
            
            // 用车时长（0：单程，1：半天，1：全天）
            if ( ! empty($post['travel'])) {
                $where['travel'] = $post['travel'];
            } else {
                $where['travel'] = 0;
            }
            // 安排与否（0：全部，1：已安排，2：未安排）
            if ($post['status'] == 1) {
                $where['a.driver_id'] = ['exp', 'is not null'];
            } elseif ($post['status'] == 2) {
                $where['a.driver_id'] = ['exp', 'is null'];
            }
            
            $res = db('meeting_car')->alias('a')
                ->join('applet_meeting_user b', 'a.user_id=b.user_id', 'LEFT')
                ->where($where)
                ->field('a.start_time,a.travel,a.purpose,b.name,(a.name) as nickname')
                ->page($page, $pagesize)
                ->select();
            foreach ($res as $key=>$val) {
                $res[$key]['start_time'] = date('Y-m-d H:i', $val['start_time']);
            }
            if ($res) {
                suc('查询成功', $res);
            } else {
                err('数据错误');
            }
        }
    }

    /**
     * @SWG\Post(
     *   path="/useHotel",
     *   tags={"Admin"},
     *   summary="员工端 - 酒店需求详情",
     *   description="员工端 - 酒店需求详情 - 黎勇斌",
     *   @SWG\Parameter(name="mstr", description="加密KEY", in="formData", required=true, type="string"),
     *   @SWG\Parameter(name="meeting_id", description="会议ID", in="formData", required=true, type="string"),
     *   @SWG\Parameter(name="time", description="// 查询时间（0：全部，1：今天，2：明天）", in="formData", required=true, type="string"),
     *   @SWG\Parameter(name="status", description="// 安排与否（0：全部，1：已安排，2：未安排）", in="formData", required=true, type="string"),
     *   @SWG\Response(
     *       response=200,
     *       description="成功返回数据",
     *       @SWG\Header(header="name", type="string", description="姓名"),
     *       @SWG\Header(header="start_time", type="string", description="时间pur"),
     *       @SWG\Header(header="purpose", type="string", description="用途（0：接机，1：送机，2：市内）"),
     *       @SWG\Header(header="nickname", type="string", description="司机"),
     *   )
     * )
     */
    public function useHotel()
    {
        $now = time();
        
        $todStart = strtotime(date('Y-m-d 00:00:00', $now));
        $todEnd = strtotime(date('Y-m-d 23:59:59', $now));
        
        $tomTime = strtotime('+1 day', $now);
        $tomStart = strtotime(date('Y-m-d 00:00:00', $tomTime));
        $tomEnd = strtotime(date('Y-m-d 23:59:59', $tomTime));
        
        if (request()->isPost()) {
            $post = input('post.');
            if ( ! isset($post['page'])) {
                $post['page'] = 0;
            }
            if ( ! isset($post['pagesize'])) {
                $post['pagesize'] = 10;
            }
            $page = $post['page'];
            $pagesize = $post['pagesize'];
            $where = [];
            
            $where['a.admin_id'] = 1004;
            $where['a.meeting_id'] = $post['meeting_id'];
            $where['b.admin_id'] = 1004;
            $where['b.meeting_id'] = $post['meeting_id'];
            if ( ! empty($post['name'])) {
                $where['b.name'] = ['like', '%' . $post['name'] . '%'];
            }
            
            // 查询时间（0：全部，1：今天，2：明天）
            if ($post['time'] == 1) {
                $where['c.start_time'] = ['between', [$todStart, $todEnd]];
            } elseif ($post['time'] == 2) {
                $where['c.start_time'] = ['between', [$tomStart, $tomEnd]];
            }
            
            // 安排与否（0：全部，1：已安排，2：未安排）
            if ($post['status'] == 1) {
                $where['a.hotel_id'] = ['exp', 'is not null'];
            } elseif ($post['status'] == 2) {
                $where['a.hotel_id'] = ['exp', 'is null'];
            }
            
            $res = db('meeting_travel')->alias('a')
                ->join('applet_meeting_user b', 'a.user_id=b.user_id', 'LEFT')
                ->join('applet_meeting_hotel c', 'a.hotel_id=c.id', 'LEFT')
                ->where($where)
                ->field('a.back_end_date,(a.id) as travel_id,a.hotel_id,b.name,(c.name) as title,c.number,c.start_time,c.type')
                ->page($page, $pagesize)
                ->select();
            foreach ($res as $key=>$val) {
                if ( ! empty($val['start_time'])) {
                    $res[$key]['start_time'] = date('Y-m-d', $val['start_time']);
                }
                if ( ! empty($val['back_end_date'])) {
                    $res[$key]['back_end_date'] = date('Y-m-d', $val['back_end_date']);
                }
            }
            
            if ($res) {
                suc('查询成功', $res);
            } else {
                err('数据错误');
            }
        }
    }
    
    // 所有酒店
    public function allHotel()
    {
        $res = db('meeting_hotel')->where(['admin_id'=>1004, 'status'=>0])->field('id,name')->select();
        
        suc('查询成功', $res);
    }

    /**
     * @SWG\Post(
     *   path="/userHotelEdit",
     *   tags={"Admin"},
     *   summary="员工端 - 酒店需求更改",
     *   description="员工端 - 酒店需求更改 - 黎勇斌",
     *   @SWG\Parameter(name="mstr", description="加密KEY", in="formData", required=true, type="string"),
     *   @SWG\Parameter(name="hotel_id", description="酒店ID", in="formData", required=true, type="string"),
     *   @SWG\Parameter(name="name", description="酒店名称", in="formData", required=true, type="string"),
     *   @SWG\Parameter(name="number", description="酒店房号", in="formData", required=true, type="string"),
     *   @SWG\Parameter(name="start_time", description="入住时间", in="formData", required=true, type="string"),
     *   @SWG\Response(
     *       response=200,
     *       description="成功返回数据",
     *   )
     * )
     */
    public function userHotelEdit()
    {
        if (request()->isPost()) {
            $post = input('post.');
            
            if (empty($post['new_hotel_id'])) {
                $data['number'] = $post['number'];
                $data['type'] = $post['type'];
                $data['start_time'] = strtotime($post['start_time']);
                $data['status'] = 1;
                
                $res = db('meeting_hotel')->where(['id'=>$post['old_hotel_id']])->update($data);
                if ($res) {
                    suc('修改成功');
                } else {
                    err('修改失败');
                }
            } else {
                if ($post['old_hotel_id'] == $post['new_hotel_id']) {
                    $data['number'] = $post['number'];
                    $data['type'] = $post['type'];
                    $data['start_time'] = strtotime($post['start_time']);
                    $data['status'] = 1;
                    
                    $res = db('meeting_hotel')->where(['id'=>$post['old_hotel_id']])->update($data);
                    if ($res) {
                        suc('修改成功');
                    } else {
                        err('修改失败');
                    }
                } else {
                    $data['number'] = $post['number'];
                    $data['type'] = $post['type'];
                    $data['start_time'] = strtotime($post['start_time']);
                    $data['status'] = 1;
                    db('meeting_hotel')->where(['id'=>$post['new_hotel_id']])->update($data);
                    db('meeting_hotel')->where(['id'=>$post['old_hotel_id']])->update(['status'=>0]);
                    $res = db('meeting_travel')->where(['id'=>$post['travel_id']])->update(['hotel_id'=>$post['new_hotel_id'], 'start_time'=>strtotime($post['start_time'])]);
                    if ($res) {
                        suc('修改成功');
                    } else {
                        err('修改失败');
                    }
                }
            }
        }
    }

    /**
     * @SWG\Post(
     *   path="/useTravel",
     *   tags={"Admin"},
     *   summary="员工端 - 行程详情",
     *   description="员工端 - 行程详情 - 黎勇斌",
     *   @SWG\Parameter(name="mstr", description="加密KEY", in="formData", required=true, type="string"),
     *   @SWG\Parameter(name="meeting_id", description="会议ID", in="formData", required=true, type="string"),
     *   @SWG\Parameter(name="go", description="// 到达行程 安排与否（0：全部，1：已填写，2：未填写）", in="formData", required=true, type="string"),
     *   @SWG\Parameter(name="back", description="// 返程行程 安排与否（0：全部，1：已填写，2：未填写）", in="formData", required=true, type="string"),
     *   @SWG\Response(
     *       response=200,
     *       description="成功返回数据",
     *       @SWG\Header(header="vehicle", type="string", description="交通工具（1：飞机，2：高铁，3：自理，4：本地）"),
     *       @SWG\Header(header="name", type="string", description="姓名"),
     *       @SWG\Header(header="mobile", type="string", description="手机号"),
     *       @SWG\Header(header="go_flight_number", type="string", description="到达航班"),
     *       @SWG\Header(header="back_flight_number", type="string", description="返程航班"),
     *   )
     * )
     */
    public function useTravel()
    {
        if (request()->isPost()) {
            $post = input('post.');
            if ( ! isset($post['page'])) {
                $post['page'] = 0;
            }
            if ( ! isset($post['pagesize'])) {
                $post['pagesize'] = 10;
            }
            $page = $post['page'];
            $pagesize = $post['pagesize'];
            
            $where = [];
            $where['a.admin_id'] = 1004;
            $where['a.meeting_id'] = $post['meeting_id'];
            
            if ( ! empty($post['name'])) {
                $where['a.name'] = ['like', '%' . $post['name'] . '%'];
            }
            // 到达行程 安排与否（0：全部，1：已填写，2：未填写）
            if ($post['go'] == 1) {
                $where['go_flight_number'] = ['exp', 'is not null'];
            } elseif ($post['go'] == 2) {
                $where['go_flight_number'] = ['exp', 'is null'];
            }
            // 返程行程 安排与否（0：全部，1：已填写，2：未填写）
            if ($post['back'] == 1) {
                $where['back_flight_number'] = ['exp', 'is not null'];
            } elseif ($post['back'] == 2) {
                $where['back_flight_number'] = ['exp', 'is null'];
            }
            
            $res = db('meeting_user')->alias('a')
                ->where($where)
                ->join('applet_meeting_travel w', 'a.user_id = w.user_id', 'LEFT')
                ->field('(w.id) as travel_id,vehicle,a.name,a.mobile,go_start_date,go_flight_number,go_start_addr,go_end_addr,go_start_time,go_end_time,back_end_date,back_flight_number,back_start_addr,back_end_addr,back_start_time,back_end_time,item')
                ->page($page, $pagesize)
                ->select();
            foreach ($res as $key=>$val) {
                $res[$key]['go_start_date'] = date('Y-m-d', $res[$key]['go_start_date']);
                $res[$key]['back_end_date'] = date('Y-m-d', $res[$key]['back_end_date']);
            }
            if ($res) {
                suc('查询成功', $res);
            } else {
                err('数据错误');
            }
        }
    }

    /**
     * @SWG\Post(
     *   path="/meetingDetails",
     *   tags={"Admin"},
     *   summary="员工端 - 会议详情",
     *   description="员工端 - 会议详情 - 黎勇斌",
     *   @SWG\Parameter(name="mstr", description="加密KEY", in="formData", required=true, type="string"),
     *   @SWG\Parameter(name="meeting_id", description="会议ID", in="formData", required=true, type="string"),
     *   @SWG\Response(
     *       response=200,
     *       description="成功返回数据",
     *       @SWG\Header(header="id", type="string", description="会议ID"),
     *       @SWG\Header(header="img", type="string", description="会议大图"),
     *       @SWG\Header(header="title", type="string", description="会议名称"),
     *       @SWG\Header(header="going_time", type="string", description="会议具体时间"),
     *       @SWG\Header(header="address", type="string", description="会议地点"),
     *       @SWG\Header(header="mobile", type="string", description="会议电话"),
     *       @SWG\Header(header="about", type="string", description="会议简介"),
     *       @SWG\Header(header="reg_name", type="string", description="注册区姓名"),
     *       @SWG\Header(header="reg_mobile", type="string", description="注册区电话"),
     *       @SWG\Header(header="stay_name", type="string", description="住宿区姓名"),
     *       @SWG\Header(header="stay_mobile", type="string", description="住宿区电话"),
     *       @SWG\Header(header="vip_name", type="string", description="VIP区姓名"),
     *       @SWG\Header(header="vip_mobile", type="string", description="VIP区电话"),
     *       @SWG\Header(header="content", type="string", description="内容"),
     *       @SWG\Header(header="agenda", type="string", description="会议日程"),
     *   )
     * )
     */
    public function meetingDetails()
    {
        $post = request()->only(['meeting_id'], 'post');
        
        $res = db('meeting_details')->where(['id'=>$post['meeting_id']])->field('id,img,title,going_date,going_date_end,address,mobile,about,content,contents,agenda,grade,longitude,latitude')->find();
        
        $res['going_time'] = date("Y/m/d", $res['going_date']) . '-' . date("Y/m/d", $res['going_date_end']);
        $res['grade'] = json_decode($res['grade']);
        
        $data = [];
        foreach ($res['grade'] as $key=>$value) {
            $data[] = explode('-', $value);
        }
        
        $res['responsible'] = $data;
        $res['img'] = json_decode($res['img']);
        
        if ($res) {
            suc('查询成功', $res);
        } else {
            err('数据错误');
        }
    }
    
    // 新用车需求提醒
    public function clock()
    {
        $post = request()->only(['meeting_id'], 'post');
        $res = db('meeting_car')->where(['meeting_id'=>$post['meeting_id']])->count();
        $info = db('meeting_config')->where(['config_name'=>$post['meeting_id'], 'status'=>0])->find();
        if ( ! $info) {
            db('meeting_config')->insert(['config_name'=>$post['meeting_id'], 'config_value'=>$res, 'status'=>0]);
            suc($res);
        } else {
            if ($res > $info['config_value']) {
                db('meeting_config')->where(['config_name'=>$post['meeting_id'], 'status'=>0])->update(['config_value'=>$res]);
                $num = $res - $info['config_value'];
                suc($num);
            } else {
                err('没有新增');
            }
        }
    }

    /**
     * @SWG\Post(
     *   path="/user",
     *   tags={"Admin"},
     *   summary="员工端 - 嘉宾状态",
     *   description="员工端 - 嘉宾状态 - 黎勇斌",
     *   @SWG\Parameter(name="mstr", description="加密KEY", in="formData", required=true, type="string"),
     *   @SWG\Parameter(name="meeting_id", description="会议ID", in="formData", required=true, type="string"),
     *   @SWG\Response(
     *       response=200,
     *       description="成功返回数据",
     *       @SWG\Header(header="name", type="string", description="嘉宾姓名"),
     *       @SWG\Header(header="mobile", type="string", description="嘉宾电话"),
     *       @SWG\Header(header="sign", type="string", description="是否签到（0：否，1：是）"),
     *       @SWG\Header(header="go_flight_number", type="string", description="到达航班"),
     *       @SWG\Header(header="go_start_date", type="string", description="到达航班 降落时间"),
     *       @SWG\Header(header="back_flight_number", type="string", description="返程航班"),
     *       @SWG\Header(header="back_end_date", type="string", description="返程航班 起飞时间"),
     *       @SWG\Header(header="location", type="string", description="司机定位"),
     *   )
     * )
     */
    public function user()
    {
        if (request()->isPost()) {
            $post = input('post.');
            if ( ! isset($post['page'])) {
                $post['page'] = 0;
            }
            if ( ! isset($post['pagesize'])) {
                $post['pagesize'] = 10;
            }
            $page = $post['page'];
            $pagesize = $post['pagesize'];
            $res = [];
            $where = [];
            $where['a.admin_id'] = 1004;
            $where['a.meeting_id'] = $post['meeting_id'];
            if ( ! empty($post['name'])) {
                $where['a.name'] = ['like', '%' . $post['name'] . '%'];
            }
            $res = db('meeting_user')->alias('a')
                ->join('applet_meeting_travel b', 'b.id=a.travel_id')
                ->join('applet_meeting_car c', 'b.id=c.car_id', 'LEFT')
                ->join('applet_meeting_hotel d', 'd.id=b.hotel_id', 'LEFT')
                ->where($where)
                ->field('a.mobile,a.name,a.sign,b.go_flight_number,b.go_start_date,b.go_end_time,b.back_flight_number,b.back_end_date,b.back_start_time,c.purpose,c.arrange_time,b.avatarurl,(d.name) as hotel_name,d.number')
                ->page($page, $pagesize)
                ->select();
            foreach ($res as $key=>$val) {
                if ( ! empty($val['go_start_date'])) {
                    $res[$key]['go_start_date'] = date('m-d', $val['go_start_date']);
                    $res[$key]['go_start_date'] = $res[$key]['go_start_date'] . " " . $val['go_end_time'];
                }
                if ( ! empty($val['back_end_date'])) {
                    $res[$key]['back_end_date'] = date('m-d', $val['back_end_date']);
                    $res[$key]['back_end_date'] = $res[$key]['back_end_date'] . " " . $val['go_end_time'];
                }
                if ( ! empty($val['arrange_time'])) {
                    $res[$key]['arrange_time'] = date('Y-m-d H:i', $val['go_start_date']);
                }
            }
            if ($res) {
                suc('查询成功', $res);
            } else {
                err('数据错误');
            }
        }
    }

    /**
     * @SWG\Post(
     *   path="/car",
     *   tags={"Admin"},
     *   summary="员工端 - 车辆安排",
     *   description="员工端 - 车辆安排 - 黎勇斌",
     *   @SWG\Parameter(name="mstr", description="加密KEY", in="formData", required=true, type="string"),
     *   @SWG\Parameter(name="meeting_id", description="会议ID", in="formData", required=true, type="string"),
     *   @SWG\Response(
     *       response=200,
     *       description="成功返回数据",
     *       @SWG\Header(header="nickname", type="string", description="司机"),
     *       @SWG\Header(header="location", type="string", description="司机定位"),
     *       @SWG\Header(header="mobile", type="string", description="司机电话"),
     *       @SWG\Header(header="name", type="string", description="嘉宾姓名"),
     *       @SWG\Header(header="number", type="string", description="车牌"),
     *       @SWG\Header(header="color", type="string", description="颜色"),
     *       @SWG\Header(header="purpose", type="string", description="用途（0：接机，1：送机，2：市内）"),
     *       @SWG\Header(header="go_status", type="string", description="接机状态（0：正在准备，1：接机途中）"),
     *       @SWG\Header(header="go_start_date", type="string", description="日期"),
     *   )
     * )
     */
    public function car()
    {
        if (request()->isPost()) {
            $post = input('post.');
            if ( ! isset($post['page'])) {
                $post['page'] = 0;
            }
            if ( ! isset($post['pagesize'])) {
                $post['pagesize'] = 10;
            }
            $page = $post['page'];
            $pagesize = $post['pagesize'];
            
            $where = [];
            $where['a.admin_id'] = 1004;
            $where['a.meeting_id'] = $post['meeting_id'];
            if ( ! empty($post['name'])) {
                $where['b.name'] = ['like', '%' . $post['name'] . '%'];
            }
            $res = db('meeting_car')->alias('a')
                ->join('applet_meeting_user b', 'a.user_id=b.user_id')
                ->join('applet_meeting_travel d', 'd.id=b.travel_id')
                ->where($where)
                ->field('(a.name) as nickname,a.avatarurl,a.number,a.color,b.name,(d.avatarurl) as user_avatarurl,a.longitude,a.latitude,d.go_start_date,d.go_end_time,a.purpose,a.mobile')
                ->page($page, $pagesize)
                ->select();
            
            foreach ($res as $key=>$val) {
                $res[$key]['go_start_date'] = date('Y-m-d', $val['go_start_date']);
                $res[$key]['go_start_date'] = $res[$key]['go_start_date'] . " " . $val['go_end_time'];
                if (empty($val['longitude']) && empty($val['latitude'])) {
                    $res[$key]['go_status'] = 0;
                } else {
                    $res[$key]['go_status'] = 1;
                }
            }
            
            if ($res) {
                suc('查询成功', $res);
            } else {
                err('数据错误');
            }
        }
    }

    /**
     * @SWG\Post(
     *   path="/userMeeting",
     *   tags={"User"},
     *   summary="嘉宾端 - 会议详情",
     *   description="嘉宾端 - 会议详情 - 黎勇斌",
     *   @SWG\Parameter(name="mstr", description="加密KEY", in="formData", required=true, type="string"),
     *   @SWG\Response(
     *       response=200,
     *       description="成功返回数据",
     *       @SWG\Header(header="img", type="string", description="会议大图"),
     *       @SWG\Header(header="title", type="string", description="会议名称"),
     *       @SWG\Header(header="going_time", type="string", description="会议具体进行时间"),
     *       @SWG\Header(header="address", type="string", description="会议地址"),
     *       @SWG\Header(header="mobile", type="string", description="会议电话"),
     *       @SWG\Header(header="company", type="string", description="会议举办方"),
     *       @SWG\Header(header="about", type="string", description="会议简介"),
     *       @SWG\Header(header="content", type="string", description="会议内容"),
     *   )
     * )
     */
    public function userMeeting()
    {
        $user = db('meeting_user')->where(['user_id'=>$this->accessData['uid']])->find();
        
        if ( ! $user) {
            $user['id'] = $insertUserId = db('meeting_user')->insertGetId(['admin_id'=>$this->accessData['aid'], 'user_id'=>$this->accessData['uid']]);
        }
        
        $user_id = $user['id'];
        
        $res = db('meeting_details')->alias('a')
            ->join('applet_meeting_travel b', "a.id=b.meeting_id and b.user_id = $user_id", 'LEFT')
            ->where(['a.admin_id'=>1004, 'a.status'=>1])
            ->field('a.id,a.img,a.title,a.going_date,a.going_date_end,a.address,a.mobile,a.company,a.about,a.content,(b.id) as travel_id,a.longitude,a.latitude')
            ->find();
        
        if ( ! empty($res['going_date'])) {
            $res['going_time'] = date('Y/m/d', $res['going_date']) . ' - ' . date('Y/m/d', $res['going_date']);
        }
        
        if ($res) {
            // 统计代码
            $meetingId = $res['id'];
            $type = 1;
            $create_time = time();
            $this->statistics($meetingId, $type, $create_time);
            
            suc('查询成功', $res);
        } else {
            err('数据错误');
        }
    }

    /**
     * @SWG\Post(
     *   path="/type",
     *   tags={"User"},
     *   summary="嘉宾端 - 大会人员类别",
     *   description="嘉宾端 - 大会人员类别 - 黎勇斌",
     *   @SWG\Parameter(name="mstr", description="加密KEY", in="formData", required=true, type="string"),
     *   @SWG\Response(
     *       response=200,
     *       description="成功返回数据",
     *       @SWG\Header(header="name", type="string", description="名称"),
     *   )
     * )
     */
    public function type()
    {
        $res = db('meeting_user_type')->where(['admin_id'=>1004])->select();
        if ($res) {
            suc('查询成功', $res);
        } else {
            err('数据错误');
        }
    }

    /**
     * @SWG\Post(
     *   path="/travelPlanning",
     *   tags={"User"},
     *   summary="嘉宾端 - 行程规划",
     *   description="嘉宾端 - 行程规划 - 黎勇斌",
     *   @SWG\Parameter(name="mstr", description="加密KEY", in="formData", required=true, type="string"),
     *   @SWG\Parameter(name="meeting_id", description="会议ID", in="formData", required=true, type="string"),
     *   @SWG\Parameter(name="type", description="类别", in="formData", required=true, type="string"),
     *   @SWG\Parameter(name="name", description="姓名", in="formData", required=true, type="string"),
     *   @SWG\Parameter(name="gender", description="性别（男：1，女：2）", in="formData", required=true, type="string"),
     *   @SWG\Parameter(name="mobile", description="电话", in="formData", required=true, type="string"),
     *   @SWG\Parameter(name="id_card", description="身份证", in="formData", required=true, type="string"),
     *   @SWG\Parameter(name="city", description="城市", in="formData", required=true, type="string"),
     *   
     *   @SWG\Parameter(name="position", description="分会任职", in="formData", required=false, type="string"),
     *   @SWG\Parameter(name="company", description="单位", in="formData", required=false, type="string"),
     *   @SWG\Parameter(name="title", description="职称", in="formData", required=false, type="string"),
     *   @SWG\Parameter(name="travel_contact", description="行程联系人姓名", in="formData", required=false, type="string"),
     *   @SWG\Parameter(name="travel_mobile", description="行程联系人电话", in="formData", required=false, type="string"),
     *   
     *   @SWG\Parameter(name="vehicle", description="交通工具（1：飞机，2：高铁，3：自理，4：本地）", in="formData", required=false, type="string"),
     *   @SWG\Parameter(name="go_start_date", description="来程日期", in="formData", required=false, type="string"),
     *   @SWG\Parameter(name="go_flight_number", description="来程航班", in="formData", required=false, type="string"),
     *   @SWG\Parameter(name="go_travel_segment", description="来程航段", in="formData", required=false, type="string"),
     *   @SWG\Parameter(name="go_start_time", description="来程起飞时间", in="formData", required=false, type="string"),
     *   @SWG\Parameter(name="go_end_time", description="来程降落时间", in="formData", required=false, type="string"),
     *   @SWG\Parameter(name="back_start_date", description="返程日期", in="formData", required=false, type="string"),
     *   @SWG\Parameter(name="back_flight_number", description="返程航班", in="formData", required=false, type="string"),
     *   @SWG\Parameter(name="back_travel_segment", description="返程航段", in="formData", required=false, type="string"),
     *   @SWG\Parameter(name="back_start_time", description="返程起飞时间", in="formData", required=false, type="string"),
     *   @SWG\Parameter(name="back_end_time", description="返程降落时间", in="formData", required=false, type="string"),
     *   @SWG\Parameter(name="item", description="注意事项", in="formData", required=false, type="string"),
     *   @SWG\Response(
     *       response=200,
     *       description="成功返回数据",
     *   )
     * )
     */
    public function travelPlanning()
    {
        if (request()->isPost()) {
            $post = input('post.');
            
            // meeting_user表
            $data['meeting_id'] = $post['meeting_id'];
            $data['user_id'] = $this->accessData['uid'];
            $avatarurl = db('user')->where(['id'=>$this->accessData['uid']])->find();
            $data['avatarurl'] = $avatarurl['avatarurl'];
            $data['admin_id'] = 1004;
            $data['name'] = $post['name'];
            $data['gender'] = $post['gender'];
            $data['mobile'] = $post['mobile'];
            $reg = db('meeting_user')->where(['meeting_id'=>$post['meeting_id'], 'mobile'=>$post['mobile']])->find();
            
            if ($reg) {
                $data['register'] = 1;
            }
            $data['id_card'] = $post['id_card'];
            $data['city'] = $post['city'];
            $data['create_time'] = time();
            if ( ! empty($post['position'])) {
                $data['position'] = $post['position'];
            }
            if ( ! empty($post['company'])) {
                $data['company'] = $post['company'];
            }
            if ( ! empty($post['title'])) {
                $data['title'] = $post['title'];
            }
            if ( ! empty($post['travel_contact'])) {
                $data['travel_contact'] = $post['travel_contact'];
            }
            if ( ! empty($post['travel_mobile'])) {
                $data['travel_mobile'] = $post['travel_mobile'];
            }
            
            //meeting_travel表
            if ( ! empty($post['vehicle'])) {
                $info['vehicle'] = $post['vehicle'];
            }
            if ( ! empty($post['go_start_date'])) {
                $info['go_start_date'] = strtotime($post['go_start_date']);
            }
            if ( ! empty($post['go_flight_number'])) {
                $info['go_flight_number'] = $post['go_flight_number'];
            }
            if ( ! empty($post['go_start_addr'])) {
                $info['go_start_addr'] = $post['go_start_addr'];
            }
            if ( ! empty($post['go_end_addr'])) {
                $info['go_end_addr'] = $post['go_end_addr'];
            }
            if ( ! empty($post['go_start_time'])) {
                $info['go_start_time'] = $post['go_start_time'];
            }
            if ( ! empty($post['go_end_time'])) {
                $info['go_end_time'] = $post['go_end_time'];
            }
            if ( ! empty($post['back_end_date'])) {
                $info['back_end_date'] = strtotime($post['back_end_date']);
            }
            if ( ! empty($post['back_flight_number'])) {
                $info['back_flight_number'] = $post['back_flight_number'];
            }
            if ( ! empty($post['back_start_addr'])) {
                $info['back_start_addr'] = $post['back_start_addr'];
            }
            if ( ! empty($post['back_end_addr'])) {
                $info['back_end_addr'] = $post['back_end_addr'];
            }
            if ( ! empty($post['back_start_time'])) {
                $info['back_start_time'] = $post['back_start_time'];
            }
            if ( ! empty($post['back_end_time'])) {
                $info['back_end_time'] = $post['back_end_time'];
            }
            if ( ! empty($post['item'])) {
                $info['item'] = $post['item'];
            }
            // 检查是否导入过该嘉宾（手机号匹配）
            $check = db('meeting_user')->where(['mobile'=>$data['mobile'], 'meeting_id'=>$data['meeting_id']])->find();
            if ($check) {
                db('meeting_user')->where(['id'=>$check['id']])->update($data);
                $res = $check['id'];
            } else {
                $res = db('meeting_user')->insertGetId($data);
            }
            
            if ( ! empty($info)) {
                $meetingId = $post['meeting_id'];
                $type = 2;
                $create_time = time();
                $this->statistics($meetingId, $type, $create_time);
                $info['meeting_id'] = $post['meeting_id'];
                $info['name'] = $post['name'];
                $info['mobile'] = $post['mobile'];
                $info['admin_id'] = 1004;
                $info['user_id'] = $res;
                $avatarurl = db('user')->where(['id'=>$this->accessData['uid']])->field('avatarurl')->find();
                $info['avatarurl'] = $avatarurl['avatarurl'];
                $info['create_time'] = time();
                $result = db('meeting_travel')->insertGetId($info);
                if ($result) {
                    db('meeting_user')->where(['id'=>$res])->update(['travel_id'=>$result]);
                    suc('添加成功');
                } else {
                    err('添加失败');
                }
            }
            if ($res) {
                suc('添加成功');
            } else {
                err('添加失败');
            }
        }
    }
    
    //行程短信验证
    public function travels()
    {
        $post = request()->only(['mobile', 'verify_code', 'time', 'mid'], 'post');
        
        if (empty($post['mobile'])) {
            err('请输入手机号码');
        }
        
        $mid_s = md5($post['mobile'] . $post['verify_code'] . $post['time'] . $this->signKey);
        
        if ($mid_s != $post['mid']) {
            err('验证码错误');
        }
        suc('验证成功');
    }
    
    // 行程信息
    public function travelMsg()
    {
        $post = request()->only(['travel_id'], 'post');
        $field = 'a.*,,b.gender,b.id_card,b.title,b.city,b.company,b.position,b.travel_contact,b.travel_mobile';
        $info = db('meeting_travel')->alias('a')
            ->join('meeting_user b', 'a.id = b.travel_id', 'left')
            ->where(['a.id'=>$post['travel_id']])
            ->find();
        if ( ! empty($info['go_start_date'])) {
            $info['go_start_date'] = date('Y-m-d', $info['go_start_date']);
        }
        if ( ! empty($info['back_end_date'])) {
            $info['back_end_date'] = date('Y-m-d', $info['back_end_date']);
        }
        if ($info) {
            suc($info);
        } else {
            err('查询失败');
        }
    }
    
    // 修改行程
    public function travelEdit()
    {
        if (request()->isPost()) {
            $post = input('post.');
            if ( ! empty($post['travel_id'])) {
                #2018/1/8修改
                if (isset($post['gender'])) {
                    $data['gender'] = $post['gender'];
                }
                
                if (isset($post['id_card'])) {
                    $data['id_card'] = $post['id_card'];
                }
                if (isset($post['title'])) {
                    $data['title'] = $post['title'];
                }
                if (isset($post['city'])) {
                    $data['city'] = $post['city'];
                }
                if (isset($post['company'])) {
                    $data['company'] = $post['company'];
                }
                if (isset($post['position'])) {
                    $data['position'] = $post['position'];
                }
                if (isset($post['travel_contact'])) {
                    $data['travel_contact'] = $post['travel_contact'];
                }
                if (isset($post['travel_mobile'])) {
                    $data['travel_mobile'] = $post['travel_mobile'];
                }
                
                if (isset($post['name'])) {
                    $data['name'] = $post['name'];
                    $info['name'] = $post['name'];
                }
                
                if (isset($post['vehicle'])) {
                    $info['vehicle'] = $post['vehicle'];
                }
                if (isset($post['go_start_date'])) {
                    $info['go_start_date'] = strtotime($post['go_start_date']);
                }
                if (isset($post['go_flight_number'])) {
                    $info['go_flight_number'] = $post['go_flight_number'];
                }
                if (isset($post['go_start_addr'])) {
                    $info['go_start_addr'] = $post['go_start_addr'];
                }
                if (isset($post['go_end_addr'])) {
                    $info['go_end_addr'] = $post['go_end_addr'];
                }
                if (isset($post['go_start_time'])) {
                    $info['go_start_time'] = $post['go_start_time'];
                }
                if (isset($post['go_end_time'])) {
                    $info['go_end_time'] = $post['go_end_time'];
                }
                if (isset($post['back_end_date'])) {
                    $info['back_end_date'] = strtotime($post['back_end_date']);
                }
                if (isset($post['back_flight_number'])) {
                    $info['back_flight_number'] = $post['back_flight_number'];
                }
                if (isset($post['back_start_addr'])) {
                    $info['back_start_addr'] = $post['back_start_addr'];
                }
                if (isset($post['back_end_addr'])) {
                    $info['back_end_addr'] = $post['back_end_addr'];
                }
                if (isset($post['back_start_time'])) {
                    $info['back_start_time'] = $post['back_start_time'];
                }
                if (isset($post['back_end_time'])) {
                    $info['back_end_time'] = $post['back_end_time'];
                }
                if (isset($post['item'])) {
                    $info['item'] = $post['item'];
                }
                
                $info['create_time'] = time();
                if ( ! empty($data)) {
                    db('meeting_user')->where(['travel_id'=>$post['travel_id']])->update($data);
                }
                
                $res = db('meeting_travel')->where(['id'=>$post['travel_id']])->update($info);
                
                if ($res) {
                    $travel = db('meeting_travel')->where(['id'=>$post['travel_id']])->find();
                    //判断是否存在
                    $str = db('meeting_travel_copy')->find(['id'=>$travel['id']]);
                    if ( ! $str) {
                        $data = [];
                        $data['id'] = $travel['id'];
                        $data['admin_id'] = $travel['admin_id'];
                        $data['name'] = $travel['name'];
                        $data['mobile'] = $travel['mobile'];
                        $data['avatarurl'] = $travel['avatarurl'];
                        $data['user_id'] = $travel['user_id'];
                        $data['meeting_id'] = $travel['meeting_id'];
                        $data['hotel_id'] = $travel['hotel_id'];
                        $data['vehicle'] = $travel['vehicle'];
                        $data['go_start_date'] = $travel['go_start_date'];
                        $data['go_flight_number'] = $travel['go_flight_number'];
                        $data['go_status'] = $travel['hotel_id'];
                        $data['go_price'] = $travel['go_price'];
                        $data['go_car'] = $travel['go_car'];
                        $data['go_start_time'] = $travel['go_start_time'];
                        $data['go_end_time'] = $travel['go_end_time'];
                        $data['back_end_date'] = $travel['back_end_date'];
                        $data['back_flight_number'] = $travel['back_flight_number'];
                        $data['back_status'] = $travel['back_status'];
                        $data['back_price'] = $travel['back_price'];
                        $data['back_car'] = $travel['back_car'];
                        $data['back_start_time'] = $travel['back_start_time'];
                        $data['back_end_time'] = $travel['back_end_time'];
                        $data['go_start_addr'] = $travel['go_start_addr'];
                        $data['go_end_addr'] = $travel['go_end_addr'];
                        $data['back_start_addr'] = $travel['back_start_addr'];
                        $data['back_end_addr'] = $travel['back_end_addr'];
                        $data['item'] = $travel['item'];
                        $data['go_money_change'] = 0;
                        $data['go_service_change'] = 0;
                        $data['back_money_change'] = 0;
                        $data['back_service_change'] = 0;
                        $data['go_solo'] = 0;
                        $data['back_solo'] = 0;
                        $data['create_time'] = time();
                        
                        db('meeting_travel_copy')->insert($data);
                    }
                    suc('修改成功');
                } else {
                    err('修改失败');
                }
            }
        }
    }

    /**
     * @SWG\Post(
     *   path="/myTravel",
     *   tags={"Admin"},
     *   summary="嘉宾端 - 我的行程",
     *   description="嘉宾端 - 我的行程 - 黎勇斌",
     *   @SWG\Parameter(name="mstr", description="加密KEY", in="formData", required=true, type="string"),
     *   @SWG\Response(
     *       response=200,
     *       description="成功返回数据",
     *       @SWG\Header(header="meeting_title", type="string", description="会议名称"),
     *       @SWG\Header(header="meeting_mobile", type="string", description="嘉宾电话"),
     *       @SWG\Header(header="meeting_going_time", type="string", description="具体开会时间"),
     *       @SWG\Header(header="meeting_address", type="string", description="开会地点"),
     *       
     *       @SWG\Header(header="travel_vehicle", type="string", description="交通工具"),
     *       @SWG\Header(header="travel_go_start_date", type="string", description="到达航班日期"),
     *       @SWG\Header(header="travel_go_flight_number", type="string", description="到达航班"),
     *       @SWG\Header(header="travel_go_start_addr", type="string", description="到达航班 出发地点"),
     *       @SWG\Header(header="travel_go_end_addr", type="string", description="到达航班 目标地点"),
     *       @SWG\Header(header="travel_go_start_time", type="string", description="到达航班 起飞时间"),
     *       @SWG\Header(header="travel_go_end_time", type="string", description="到达航班 降落时间"),
     *       @SWG\Header(header="travel_back_end_date", type="string", description="返程航班日期"),
     *       @SWG\Header(header="travel_back_flight_number", type="string", description="返程航班"),
     *       @SWG\Header(header="travel_back_start_addr", type="string", description="返程航班 出发"),
     *       @SWG\Header(header="travel_back_end_addr", type="string", description="返程航班 目标"),
     *       @SWG\Header(header="travel_back_start_time", type="string", description="返程航班 起飞"),
     *       @SWG\Header(header="travel_back_end_time", type="string", description="返程航班 降落"),
     *
     *       @SWG\Header(header="hotel_type", type="string", description="房型"),
     *       @SWG\Header(header="hotel_name", type="string", description="酒店名称"),
     *       @SWG\Header(header="hotel_number", type="string", description="房间号"),
     *       @SWG\Header(header="hotel_start_time", type="string", description="入住时间"),
     *       @SWG\Header(header="hotel_location", type="string", description="定位"),
     *       @SWG\Header(header="hotel_mobile", type="string", description="电话"),
     *       
     *       @SWG\Header(header="car_name", type="string", description="司机"),
     *       @SWG\Header(header="car_purpose", type="string", description="用途（0：接机，1：送机，2：市内"),
     *       @SWG\Header(header="car_mobile", type="string", description="电话"),
     *       @SWG\Header(header="car_number", type="string", description="车牌"),
     *       @SWG\Header(header="car_color", type="string", description="车辆-颜色"),
     *   )
     * )
     */
    public function myTravel()
    {
        $post = request()->only(['longitude', 'latitude']);
        $res = [];
        $res['meeting'] = db('meeting_details')->where(['admin_id'=>1004, 'status'=>1])->field('id,title,mobile,going_time,address,longitude,latitude,going_date,going_date_end,longitude,latitude')->find();
        if ( ! empty($res['meeting'])) {
            if (time() > $res['meeting']['going_date_end']) {
                $res['meeting']['question'] = 1;
            } else {
                $res['meeting']['question'] = 0;
            }
            $res['meeting']['going_time'] = date('Y/m/d', $res['meeting']['going_date']) . ' - ' . date('Y/m/d', $res['meeting']['going_date']);
        }
        if ( ! empty($res['meeting'])) {
            $res['travel'] = db('meeting_user')->where(['a.user_id'=>$this->accessData['uid'], 'a.meeting_id'=>$res['meeting']['id']])
                ->alias('a')
                ->join('applet_meeting_travel b', 'b.user_id=a.id')
                ->field(
                                            'a.register,b.id,b.vehicle,go_start_date,go_flight_number,go_start_addr,go_start_addr,go_end_addr,go_start_time,go_end_time,back_end_date,back_flight_number,back_flight_number,back_start_addr,back_end_addr,back_start_time,back_end_time,b.id,a.type,b.go_money,b.back_money,a.task_url')
                ->find();
            if ( ! empty($res['travel']['go_start_date'])) {
                $res['travel']['go_start_date'] = date('Y-m-d', $res['travel']['go_start_date']);
            }
            if ( ! empty($res['travel']['back_end_date'])) {
                $res['travel']['back_end_date'] = date('Y-m-d', $res['travel']['back_end_date']);
            }
            // 人员类别对应状态
            $res['type'] = db('meeting_user_type')->where(['id'=>$res['travel']['type']])->field('plane_status,hotel_status,car_status,reg_status,task_status')->find();
            if ($res['type']['plane_status'] == 1) {
                if ($res['travel']['go_money'] == '') {
                    $res['type']['plane_status_go'] = 3;
                } else {
                    $res['type']['plane_status_go'] = 4;
                }
                
                if ($res['travel']['back_money'] == '') {
                    $res['type']['plane_status_back'] = 3;
                } else {
                    $res['type']['plane_status_back'] = 4;
                }
            } else {
                $res['type']['plane_status_go'] = '';
                $res['type']['plane_status_back'] = '';
            }
        }
        $res['hotel'] = db('meeting_user')->where(['a.user_id'=>$this->accessData['uid'], 'a.meeting_id'=>$res['meeting']['id']])
            ->alias('a')
            ->join('applet_meeting_travel b', 'b.user_id=a.id')
            ->join('applet_meeting_hotel c', 'b.hotel_id=c.id')
            ->field('c.type,c.name,c.number,c.thumb,c.start_time,c.longitude,c.latitude,c.mobile')
            ->find();
        if ( ! empty($res['hotel']['longitude']) &&  ! empty($res['car']['latitude'])) {
            $lng1 = $res['meeting']['longitude'];
            $lat1 = $res['meeting']['latitude'];
            $lng2 = $res['hotel']['longitude'];
            $lat2 = $res['hotel']['latitude'];
            $res['hotel']['location_meeting_hotel'] = round($this->getdistance($lng1, $lat1, $lng2, $lat2) / 1000, 2);
        }
        if ( ! empty($res['hotel'])) {
            $res['hotel']['start_time'] = date('Y-m-d', $res['hotel']['start_time']);
        }
        
        $res['car'] = db('meeting_user')->alias('a')
            ->where(['a.user_id'=>$this->accessData['uid'], 'a.meeting_id'=>$res['meeting']['id'], 'c.status'=>0])
            ->join('applet_meeting_car c', 'a.id=c.user_id')
            ->field('c.id,c.car_id,c.name,c.purpose,c.mobile,c.number,c.color,c.longitude,c.latitude,c.arrange_time,c.go_contacts_name,c.go_contacts_mobile')
            ->order('c.id desc')
            ->select();
        foreach ($res['car'] as $k=>$v) {
            if ( ! empty($v['arrange_time'])) {
                $res['car'][$k]['arrange_time'] = date("Y-m-d H:i:s", $v['arrange_time']);
            }
        }
        if ( ! empty($res['car']['longitude']) &&  ! empty($res['car']['latitude'])) {
            foreach ($res['car'] as $key=>$val) {
                $lng1 = $post['longitude'];
                $lat1 = $post['latitude'];
                $lng2 = $val['longitude'];
                $lat2 = $val['latitude'];
                $res['car'][$key]['location_me_car'] = round($this->getdistance($lng1, $lat1, $lng2, $lat2) / 1000, 2);
            }
            // 查询车辆最新定位
            $info = db('meeting_location')->where(['car_id'=>$res['car']['car_id']])->order('create_time desc')->find();
            // 更新用车最后定位
            db('meeting_car')->where(['car_id'=>$info['car_id']])->update(['longitude'=>$info['longitude'], 'latitude'=>$info['latitude']]);
        }
        
        if ($res) {
            suc('查询成功', $res);
        } else {
            err('数据错误');
        }
    }

    /**
     * @SWG\Post(
     *   path="/applyCar",
     *   tags={"Master"},
     *   summary="嘉宾端 - 用车申请",
     *   description="嘉宾端 - 用车申请 - 黎勇斌",
     *   @SWG\Parameter(name="mstr", description="加密KEY", in="formData", required=true, type="string"),
     *   @SWG\Parameter(name="meeting_id", description="会议ID", in="formData", required=true, type="string"),
     *   @SWG\Parameter(name="purpose", description="// 用途（0：接机，1：送机，2：市内）", in="formData", required=true, type="string"),
     *   @SWG\Parameter(name="travel", description="// 用车时长（0：单程，1：半天，2：全天）", in="formData", required=true, type="string"),
     *   @SWG\Parameter(name="start_addr", description="出发地", in="formData", required=true, type="string"),
     *   @SWG\Parameter(name="end_addr", description="目的地", in="formData", required=true, type="string"),
     *   @SWG\Response(
     *       response=200,
     *       description="成功返回数据",
     *   )
     * )
     */
    public function applyCar()
    {
        $user = db('meeting_user')->where(['user_id'=>$this->accessData['uid']])->find();
        
        if (request()->isPost()) {
            $post = input('post.');
            $data['meeting_id'] = $post['meeting_id'];
            $data['admin_id'] = 1004;
            $data['user_id'] = $user['id'];
            $data['purpose'] = 2;
            $data['travel'] = $post['travel'];
            $data['start_addr'] = $post['start_addr'];
            $data['end_addr'] = $post['end_addr'];
            $data['start_time'] = strtotime($post['start_time']);
            $data['create_time'] = time();
            $data['user_name'] = $user['name'];
            $data['user_mobile'] = $user['mobile'];
            $res = db('meeting_car')->insert($data);
            if ($res) {
                suc('添加成功');
            } else {
                err('添加失败');
            }
        }
    }
    
    // 司机端 - 登陆
    public function loginMaster()
    {
        $post = request()->only(['mobile', 'verify_code', 'time', 'mid'], 'post');
        
        if (empty($post['mobile'])) {
            err('请输入手机号码');
        }
        $mid_s = md5($post['mobile'] . $post['verify_code'] . $post['time'] . $this->signKey);
        
        $info = db('user')->where(['mobile'=>$post['mobile'], 'status'=>2, 'admin_id'=>[['=', 1005], ['=', 1004], 'or']])->find();
        // dump($info);die;
        if (empty($info)) {
            err('该账号无登陆权限');
        }
        if ($mid_s != $post['mid']) {
            err('验证码错误');
        }
        suc('验证成功');
    }

    /**
     * @SWG\Post(
     *   path="/allCar",
     *   tags={"Master"},
     *   summary="司机端 - 所有车",
     *   description="司机端 - 所有车 - 黎勇斌",
     *   @SWG\Parameter(name="mstr", description="加密KEY", in="formData", required=true, type="string"),
     *   @SWG\Response(
     *       response=200,
     *       description="成功返回数据",
     *       @SWG\Header(header="id", type="string", description="车ID"),
     *       @SWG\Header(header="color", type="string", description="车辆-颜色"),
     *       @SWG\Header(header="number", type="string", description="车牌"),
     *   )
     * )
     */
    public function allCar()
    {
        $res = db('meeting_user_car')->where(['admin_id'=>1004])->field('id,color,number')->select();
        
        if ($res) {
            suc('查询成功', $res);
        } else {
            err('数据错误');
        }
    }

    /**
     * @SWG\Post(
     *   path="/choice",
     *   tags={"Master"},
     *   summary="司机端 - 选择车",
     *   description="司机端 - 选择车 - 黎勇斌",
     *   @SWG\Parameter(name="mstr", description="加密KEY", in="formData", required=true, type="string"),
     *   @SWG\Response(
     *       response=200,
     *       description="成功返回数据",
     *   )
     * )
     */
    public function choice()
    {
        $post = request()->only(['car_id'], 'post');
        
        $where = [];
        $where['driver_id'] = $this->accessData['uid'];
        $where['id'] = $post['car_id'];
        $info = db('meeting_user_car')->where($where)->find();
        if ($info) {
            suc('选择成功');
        } else {
            $res = db('meeting_user_car')->where(['id'=>$post['car_id']])->update(['driver_id'=>$this->accessData['uid']]);
            if ($res) {
                suc('选择成功');
            } else {
                err('选择失败');
            }
        }
    }

    /**
     * @SWG\Post(
     *   path="/orderAll",
     *   tags={"Master"},
     *   summary="司机端 - 待完成订单",
     *   description="司机端 - 待完成订单 - 黎勇斌",
     *   @SWG\Parameter(name="mstr", description="加密KEY", in="formData", required=true, type="string"),
     *   @SWG\Response(
     *       response=200,
     *       description="成功返回数据",
     *       @SWG\Header(header="purpose", type="string", description="用途（0：接机，1：送机，2：市内）"),
     *       @SWG\Header(header="go_end_addr", type="string", description="机场"),
     *       @SWG\Header(header="name", type="string", description="姓名"),
     *       @SWG\Header(header="go_flight_number", type="string", description="航班"),
     *       @SWG\Header(header="mobile", type="string", description="电话"),
     *       @SWG\Header(header="airport_time", type="string", description="接机时间"),
     *       @SWG\Header(header="hotel_name", type="string", description="酒店名称"),
     *   )
     * )
     */
    public function orderAll()
    {
        $now = time();
        
        $todStart = strtotime(date('Y-m-d 00:00:00', $now));
        $todEnd = strtotime(date('Y-m-d 23:59:59', $now));
        
        $tomTime = strtotime('+1 day', $now);
        $tomStart = strtotime(date('Y-m-d 00:00:00', $tomTime));
        $tomEnd = strtotime(date('Y-m-d 23:59:59', $tomTime));
        if (request()->isPost()) {
            $post = input('post.');
            if ( ! isset($post['page'])) {
                $post['page'] = 0;
            }
            if ( ! isset($post['pagesize'])) {
                $post['pagesize'] = 10;
            }
            $page = $post['page'];
            $pagesize = $post['pagesize'];
            $where = [];
            // 查询时间（0：全部，1：今天，2：明天）
            if ($post['time'] == 1) {
                $where['arrange_time'] = ['between', [$todStart, $todEnd]];
            } elseif ($post['time'] == 2) {
                $where['arrange_time'] = ['between', [$tomStart, $tomEnd]];
            }
            
            $where['a.driver_id'] = $this->accessData['uid'];
            $where['b.status'] = 0;
            $res = db('meeting_user_car')->alias('a')
                ->join('applet_meeting_car b', 'b.car_id=a.id')
                ->join('applet_meeting_travel c', 'c.user_id=b.user_id')
                ->join('applet_meeting_hotel d', 'd.id=c.hotel_id')
                ->where($where)
                ->field('b.id,b.purpose,c.go_end_addr,c.go_start_date,c.go_end_time,c.name,c.go_flight_number,c.mobile,(d.name) as hotel_name,arrange_time,d.longitude,d.latitude')
                ->order('arrange_time desc')
                ->page($page, $pagesize)
                ->select();
            
            foreach ($res as $key=>$val) {
                if ( ! empty($val['go_start_date']) &&  ! empty($val['go_end_time'])) {
                    $res[$key]['airport_time'] = date('Y-m-d', $val['go_start_date']) . " " . $val['go_end_time'];
                }
                if ( ! empty($val['arrange_time'])) {
                    $res[$key]['arrange_time'] = date('Y-m-d H:i', $val['arrange_time']);
                }
            }
            if ($res) {
                suc('查询成功', $res);
            } else {
                err('数据错误');
            }
        }
    }
    
    // 确认订单完成
    public function changeOrder()
    {
        $post = request()->only(['id'], 'post');
        
        $res = db('meeting_car')->where(['id'=>$post['id']])->update(['status'=>1, 'user_id'=>$this->accessData['uid'], 'order_time'=>time()]);
        if ($res) {
            suc('修改成功');
        } else {
            err('修改失败');
        }
    }
    
    // 空驶
    public function changeOrderEig()
    {
        $post = request()->only(['id'], 'post');
        
        $res = db('meeting_car')->where(['id'=>$post['id']])->update(['status'=>1, 'eig_status'=>1, 'user_id'=>$this->accessData['uid'], 'order_time'=>time()]);
        if ($res) {
            suc('修改成功');
        } else {
            err('修改失败');
        }
    }

    /**
     * @SWG\Post(
     *   path="/orderPaid",
     *   tags={"Master"},
     *   summary="司机端 - 已完成订单",
     *   description="司机端 - 已完成订单 - 黎勇斌",
     *   @SWG\Parameter(name="mstr", description="加密KEY", in="formData", required=true, type="string"),
     *   @SWG\Parameter(name="purpose", description="// 用途（0：接机，1：送机，2：市内，全部：3）", in="formData", required=true, type="string"),
     *   @SWG\Response(
     *       response=200,
     *       description="成功返回数据",
     *       @SWG\Header(header="purpose", type="string", description="用途（0：接机，1：送机，2：市内）"),
     *       @SWG\Header(header="go_end_addr", type="string", description="机场"),
     *       @SWG\Header(header="name", type="string", description="姓名"),
     *       @SWG\Header(header="go_flight_number", type="string", description="航班"),
     *       @SWG\Header(header="mobile", type="string", description="电话"),
     *       @SWG\Header(header="airport_time", type="string", description="接机时间"),
     *       @SWG\Header(header="hotel_name", type="string", description="酒店名称"),
     *   )
     * )
     */
    public function orderPaid()
    {
        if (request()->isPost()) {
            $post = input('post.');
            $where = [];
            if ( ! isset($post['page'])) {
                $post['page'] = 0;
            }
            if ( ! isset($post['pagesize'])) {
                $post['pagesize'] = 10;
            }
            $page = $post['page'];
            $pagesize = $post['pagesize'];
            
            // 用途（0：全部，1：接机，2：送机，市内：3）
            if ($post['purpose'] == 1) {
                $where['purpose'] = 0;
            } elseif ($post['purpose'] == 2) {
                $where['purpose'] = 1;
            } elseif ($post['purpose'] == 3) {
                $where['purpose'] = 2;
            }
            $where['b.status'] = 1;
            $user = $this->accessData['uid'];
            $res = db('meeting_user_car')->alias('a')
                ->join('applet_meeting_car b', "b.car_id=a.id")
                ->join('applet_meeting_travel c', 'c.user_id=b.user_id')
                ->join('applet_meeting_hotel d', 'd.id=c.hotel_id')
                ->where($where)
                ->field('b.purpose,c.go_end_addr,c.go_start_date,c.go_end_time,c.name,c.go_flight_number,c.mobile,(d.name) as hotel_name,order_time,b.eig_status')
                ->order('arrange_time desc')
                ->page($page, $pagesize)
                ->select();
            // echo db('meeting_user_car')->getlastsql();die;
            foreach ($res as $key=>$val) {
                if ( ! empty($val['go_start_date']) &&  ! empty($val['go_end_time'])) {
                    $res[$key]['airport_time'] = date('Y-m-d', $val['go_start_date']) . " " . $val['go_end_time'];
                }
                if ( ! empty($val['order_time'])) {
                    $res[$key]['order_time'] = date('Y-m-d H:i', $val['order_time']);
                }
            }
            if ($res) {
                suc('查询成功', $res);
            } else {
                err('数据错误');
            }
        }
    }
    
    // 生成二维码
    public function png($outfile = false, $size = 3, $margin = 4, $saveandprint = false)
    {
        $post = request()->only(['text'], 'post');
        
        Vendor('phpqrcode.phpqrcode');
        $QRcode = new \QRcode();
        //    $QRcode::png($text);
        //    Header("Content-type: image/png");
        // ImagePng($QR);
        //    exit;
        $tempDir = ROOT_PATH . DS . 'public' . DS;
        
        $path = 'uploads' . DS . 1004 . DS . 'QRcode' . DS;
        
        @mkdir($path, 0777, true);
        // dump($path);die;
        

        $codeContents = $post['text'];
        
        // generating 
        $fileName = time() . '.jpg';
        // frame config values below 4 are not recomended !!! 
        $QRcode::png($codeContents, $tempDir . $path . $fileName, QR_ECLEVEL_L, 3, 4);
        $url = 'http://bike.wei-yong.com/' . $path . $fileName;
        suc($url);
        // displaying 
    }
    // 扫码
    public function sign()
    {
        $post = request()->only(['travel_id'], 'post');
        $res = db('meeting_travel')->alias('a')
            ->join('applet_meeting_user b', 'b.user_id=a.user_id')
            ->join('applet_meeting_hotel c', 'c.id=a.hotel_id')
            ->field('b.name,b.position,b.company,b.title,
					(c.name)as hotel_name,c.number,
					a.back_flight_number,a.back_start_addr,a.back_end_addr,a.back_end_date,a.back_start_time,a.back_end_time,a.vehicle')
            ->where(['a.id'=>$post['travel_id']])
            ->find();
        if ( ! empty($res)) {
            $res['back_end_date'] = date('Y-m-d', $res['back_end_date']);
        }
        if ($res) {
            suc('查询成功', $res);
        } else {
            err('数据错误');
        }
    }
    // 签到
    public function checkSign()
    {
        $post = request()->only(['travel_id'], 'post');
        $info = db('meeting_user')->where(['id'=>$post['travel_id']])->find();
        if ($info['sign'] == 1) {
            suc('该用户已签到');
        }
        $res = db('meeting_user')->where(['id'=>$post['travel_id']])->update(['sign'=>1]);
        if ($res) {
            $meetingId = $info['meeting_id'];
            $type = 3;
            $create_time = time();
            $this->statistics($meetingId, $type, $create_time);
            suc('签到成功');
        } else {
            err('签到失败');
        }
    }
    
    // 定位
    public function location()
    {
        $post = request()->only(['longitude', 'latitude', 'car_id'], 'post');
        
        $info = db('meeting_car')->where(['id'=>$post['car_id']])->find();
        
        $data['longitude'] = $post['longitude'];
        $data['latitude'] = $post['latitude'];
        $data['car_id'] = $post['car_id'];
        $data['car_name'] = $info['name'];
        $data['create_time'] = time();
        $res = db('meeting_location')->insert($data);
        if ($res) {
            suc('添加成功');
        } else {
            err('添加失败');
        }
    }

    /**
     *统计人数
     */
    public function statistics($meetingId, $type, $create_time)
    {
        $todStart = strtotime(date('Y-m-d 00:00:00', time()));
        $todEnd = strtotime(date('Y-m-d 23:59:59', time()));
        $info = db('meeting_statistics')->where(['create_time'=>['between', [$todStart, $todEnd]], 'meeting_id'=>$meetingId])->find();
        if ($type == 1) {
            if ( ! $info) {
                $data['meeting_id'] = $meetingId;
                $data['create_time'] = $create_time;
                $data['hits'] = 1;
                db('meeting_statistics')->insert($data);
            } else {
                db('meeting_statistics')->where(['id'=>$info['id']])->setInc('hits');
            }
        } elseif ($type == 2) {
            db('meeting_statistics')->where(['id'=>$info['id']])->setInc('enrolments');
        } else {
            db('meeting_statistics')->where(['id'=>$info['id']])->setInc('signs');
        }
    }
    
    // 问卷调查
    public function questionnaire()
    {
        $post = request()->only(['meeting_id'], 'post');
        
        //判断是否提交过2018/0108
        $answer = db('meeting_user_questionnaire')->where(['user_id'=>2146, 'meeting_id'=>$post['meeting_id']])->find();
        
        if ($answer) {
            // 查询问卷题目
            $resTopic = db('meeting_questionnaire')->alias('q')
                ->join('meeting_user_questionnaire u', 'q.id = u.questionnaire_id')
                ->where(['q.meeting_id'=>$post['meeting_id']])
                ->field('q.id, q.title, q.type, q.answer_a, q.answer_b, q.answer_c, q.answer_d, u.answer')
                ->order('sorts desc')
                ->limit(300)
                ->select();
            
            if ( ! $resTopic) {
                err('meeting error');
            }
            
            foreach ($resTopic as $key=>$value) {
                $i = 0;
                $returnData = [];
                
                $answerArr = json_decode($value['answer'], true);
                
                // 填空题
                if ($value['type'] == 3) {
                    foreach ($answerArr as $valAnswer) {
                        $returnData[] = $valAnswer;
                    }
                    
                    $resTopic[$key]['answers'] = $returnData;
                } else {
                    // 选择题
                    

                    if (isset($value['answer_a'])) {
                        $resTopic[$key]['answers'][$i]['answer'] = 'A:' . $value['answer_a'];
                        
                        if (array_search('A', $answerArr) !== false) {
                            $resTopic[$key]['answers'][$i]['checked'] = true;
                        } else {
                            $resTopic[$key]['answers'][$i]['checked'] = false;
                        }
                        
                        $i ++ ;
                    }
                    
                    if (isset($value['answer_b'])) {
                        $resTopic[$key]['answers'][$i]['answer'] = 'B:' . $value['answer_b'];
                        
                        if (array_search('B', $answerArr) !== false) {
                            $resTopic[$key]['answers'][$i]['checked'] = true;
                        } else {
                            $resTopic[$key]['answers'][$i]['checked'] = false;
                        }
                        
                        $i ++ ;
                    }
                    
                    if (isset($value['answer_c'])) {
                        $resTopic[$key]['answers'][$i]['answer'] = 'C:' . $value['answer_c'];
                        
                        if (array_search('C', $answerArr) !== false) {
                            $resTopic[$key]['answers'][$i]['checked'] = true;
                        } else {
                            $resTopic[$key]['answers'][$i]['checked'] = false;
                        }
                        
                        $i ++ ;
                    }
                    
                    if (isset($value['answer_d'])) {
                        $resTopic[$key]['answers'][$i]['answer'] = 'D:' . $value['answer_d'];
                        
                        if (array_search('D', $answerArr) !== false) {
                            $resTopic[$key]['answers'][$i]['checked'] = true;
                        } else {
                            $resTopic[$key]['answers'][$i]['checked'] = false;
                        }
                    }
                }
                
                $i = 0;
            }
            
            suc('查询成功', ['type'=>'finish', 'data_answer'=>$resTopic]);
        } else {
            // 查询问卷题目
            $resTopic = db('meeting_questionnaire')->where(['meeting_id'=>$post['meeting_id']])
                ->field('id,title,type,answer_a, answer_b, answer_c, answer_d')
                ->order('sorts desc')
                ->select();
            
            if ( ! $resTopic) {
                err('meeting error');
            }
            
            foreach ($resTopic as $key=>$value) {
                $i = 0;
                $returnData = [];
                
                // 填空题
                if ($value['type'] == 3) {
                    for ($i = 0; $i < $value['answer_a']; $i ++ ) {
                        $returnData[] = '';
                    }
                    
                    $resTopic[$key]['answers'] = $returnData;
                } else {
                    // 选择题
                    

                    if (isset($value['answer_a'])) {
                        $resTopic[$key]['answers'][$i]['answer'] = 'A:' . $value['answer_a'];
                        $resTopic[$key]['answers'][$i]['checked'] = false;
                        $i ++ ;
                    }
                    
                    if (isset($value['answer_b'])) {
                        $resTopic[$key]['answers'][$i]['answer'] = 'B:' . $value['answer_b'];
                        $resTopic[$key]['answers'][$i]['checked'] = false;
                        $i ++ ;
                    }
                    
                    if (isset($value['answer_c'])) {
                        $resTopic[$key]['answers'][$i]['answer'] = 'C:' . $value['answer_c'];
                        $resTopic[$key]['answers'][$i]['checked'] = false;
                        $i ++ ;
                    }
                    
                    if (isset($value['answer_d'])) {
                        $resTopic[$key]['answers'][$i]['answer'] = 'D:' . $value['answer_d'];
                        $resTopic[$key]['answers'][$i]['checked'] = false;
                    }
                }
                
                $i = 0;
            }
        }
        
        if ($resTopic) {
            suc('查询成功', ['type'=>'unfinished', 'data_answer'=>$resTopic]);
        } else {
            err('查询失败');
        }
    }
    
    // 提交问卷
    public function questionnaireSubmit()
    {
        if (request()->isPost()) {
            $post = input('post.');
            $meeting = db('meeting_details')->where(['admin_id'=>1004, 'status'=>1])->find();
            $info = db('meeting_user_questionnaire')->where(['user_id'=>$this->accessData['uid'], 'meeting_id'=>$meeting['id']])->find();
            if ($info) {
                err('已提交过该问卷');
            }
            
            $data['user_id'] = $this->accessData['uid'];
            $data['admin_id'] = 1004;
            $data['create_time'] = time();
            $data['select_content'] = json_encode($post['questionnaires']);
            $data['meeting_id'] = $meeting['id'];
            
            $res = db('meeting_user_questionnaire')->insert($data);
            if ($res) {
                suc('提交成功');
            } else {
                err('提交失败');
            }
        }
    }
    
    // 发送短信验证码到手机
    // type - 1：员工，2：司机，3：嘉宾
    public function sendNoteToMobile()
    {
        $post = request()->only(['mobile', 'type'], 'post');
        
        // 手机号格式错误
        if ( ! isMobile($post['mobile'])) {
            err('mobile error');
        }
        
        $verifyCode = mt_rand(1000, 9999);
        
        if ($post['type'] == '1') {
            $content = '您的验证码为' . $verifyCode;
        } elseif ($post['type'] == 2) {
            $content = '您的验证码为' . $verifyCode;
        } elseif ($post['type'] == 3) {
            $content = '您的验证码为' . $verifyCode;
        }
        
        if ( ! isset($content)) {
            err('Type param error');
        }
        
        if ($post['mobile'] != '18711112222') {
            $url = 'http://smsapi.c123.cn/OpenPlatform/OpenApi'; //接口地址
            $ac = '1001@500863000001'; //用户账号
            $authkey = '11E42A616C08D53C8E2A2B5D2DE21000'; //认证密钥
            $cgid = '9384'; //通道组编号
            $c = $content; //内容
            $m = $post['mobile']; //号码
            $csid = '9021'; //签名编号 ,可以为空时，使用系统默认的编号
            $t = ''; //发送时间,可以为空表示立即发送,yyyyMMddHHmmss 如:20130721182038
            

            $return = $this->sendSMS($url, $ac, $authkey, $cgid, $m, $c, $csid, $t);
        } else {
            $verifyCode = 8888;
            $return = ['code'=>1, 'msg'=>'发送成功'];
        }
        
        // 短信发送失败
        if ($return['code'] != 1) {
            err($return['msg']);
        }
        
        $resData = [];
        $resData['mobile'] = $post['mobile'];
        $resData['verify_code'] = $verifyCode;
        $resData['time'] = $this->timeStamp;
        $resData['mid'] = md5($post['mobile'] . $verifyCode . $this->timeStamp . $this->signKey);
        
        suc('success', $resData);
    }
    
    // 验证短信验证码
    public function verifyNote()
    {
        $post = request()->only(['mobile', 'time', 'mid', 'verify_code']);
        
        if ($post['mid'] != md5($post['mobile'] . $post['verify_code'] . $post['time'] . $this->signKey)) {
            err('验证失败');
        }
        
        suc();
    }

    /*
     * 程序版权：上海创明信息技有限公司 服务热线：4008885262 技术 QQ：2355373292 修改时间：2013-08-18 程序功能：创明网PHP接口示例 通过接口进行单发、群发； 接口说明: http://smsapi.c123.cn/OpenPlatform/OpenApi?action=sendOnce&ac=用户账号&authkey=认证密钥&cgid=通道组编号&c=短信内容&m=发送号码 状态: 1 操作成功 0 帐户格式不正确(正确的格式为:员工编号@企业编号) -1 服务器拒绝(速度过快、限时或绑定IP不对等)如遇速度过快可延时再发 -2 密钥不正确 -3 密钥已锁定 -4 参数不正确(内容和号码不能为空，手机号码数过多，发送时间错误等) -5 无此帐户 -6 帐户已锁定或已过期 -7 帐户未开启接口发送 -8 不可使用该通道组 -9 帐户余额不足 -10 内部错误 -11 扣费失败 短信平台： http://web.c123.cn/main 用户名：50086300 密码：med51669166 接口平台 账号:500863000001 密码:med516691661
     */
    public function sendSMS($url, $ac, $authkey, $cgid, $m, $c, $csid, $t)
    {
        $data = array(
                    //发送类型 ，可以有sendOnce短信发送，sendBatch一对一发送，sendParam	动态参数短信接口
                    'action'=>'sendOnce', 
                    //用户账号
                    'ac'=>$ac, 
                    //认证密钥
                    'authkey'=>$authkey, 
                    //通道组编号
                    'cgid'=>$cgid, 
                    //号码,多个号码用逗号隔开
                    'm'=>$m, 
                    //'c'=>iconv('gb2312','utf-8',$c),
                    //如果页面是gbk编码，则转成utf-8编码，如果是页面是utf-8编码，则不需要转码
                    'c'=>$c, 
                    
                    //签名编号 ，可以为空，为空时使用系统默认的签名编号
                    'csid'=>$csid, 
                    //定时发送，为空时表示立即发送
                    't'=>$t);
        
        $xml = $this->postSMS($url, $data); //POST方式提交
        $re = simplexml_load_string(utf8_encode($xml));
        
        //发送成功 ，返回企业编号，员工编号，发送编号，短信条数，单价，余额
        

        if (trim($re['result']) == 1) {
            foreach ($re->Item as $item) {
                
                $stat['msgid'] = trim((string)$item['msgid']);
                $stat['total'] = trim((string)$item['total']);
                $stat['price'] = trim((string)$item['price']);
                $stat['remain'] = trim((string)$item['remain']);
                $stat_arr[] = $stat;
            }
            if (is_array($stat_arr)) {
                return ['code'=>1, 'msg'=>'发送成功'];
                //echo "发送成功,返回值为" . $re['result'];
            }
        } else {
            $msg = '未知错误';
            //发送失败的返回值
            switch (trim($re['result'])) {
                case 0:
                    $msg = "帐户格式不正确(正确的格式为:员工编号@企业编号)";
                    break;
                case  - 1:
                    $msg = "服务器拒绝(速度过快、限时或绑定IP不对等)如遇速度过快可延时再发";
                    break;
                case  - 2:
                    $msg = " 密钥不正确";
                    break;
                case  - 3:
                    $msg = "密钥已锁定";
                    break;
                case  - 4:
                    $msg = "参数不正确(内容和号码不能为空，手机号码数过多，发送时间错误等)";
                    break;
                case  - 5:
                    $msg = "无此帐户";
                    break;
                case  - 6:
                    $msg = "帐户已锁定或已过期";
                    break;
                case  - 7:
                    $msg = "帐户未开启接口发送";
                    break;
                case  - 8:
                    $msg = "不可使用该通道组";
                    break;
                case  - 9:
                    $msg = "帐户余额不足";
                    break;
                case  - 10:
                    $msg = "内部错误";
                    break;
                case  - 11:
                    $msg = "扣费失败";
                    break;
                default:
                    break;
            }
            
            return ['code'=>trim($re['result']), 'msg'=>$msg];
        }
    }

    public function postSMS($url, $data = '')
    {
        $row = parse_url($url);
        $host = $row['host'];
        $port = 80;
        $file = $row['path'];
        $post = '';
        
        while (list($k, $v) = each($data)) {
            $post .= rawurlencode($k) . "=" . rawurlencode($v) . "&"; //转URL标准码
        }
        $post = substr($post, 0,  - 1);
        $len = strlen($post);
        $fp = @fsockopen($host, $port, $errno, $errstr, 10);
        if ( ! $fp) {
            return "$errstr ($errno)\n";
        } else {
            $receive = '';
            $out = "POST $file HTTP/1.0\r\n";
            $out .= "Host: $host\r\n";
            $out .= "Content-type: application/x-www-form-urlencoded\r\n";
            $out .= "Connection: Close\r\n";
            $out .= "Content-Length: $len\r\n\r\n";
            $out .= $post;
            fwrite($fp, $out);
            while ( ! feof($fp)) {
                $receive .= fgets($fp, 128);
            }
            fclose($fp);
            $receive = explode("\r\n\r\n", $receive);
            unset($receive[0]);
            return implode("", $receive);
        }
    }
}
